<template>
  <van-form @submit="onSubmit">
    <van-cell-group inset>
      <van-field
        v-model="user.username"
        name="用户名"
        label="用户名"
        placeholder="用户名"
        :rules="[{ required: true, message: '请填写用户名' }]"
      />
      <van-field
        v-model="user.pwd"
        type="password"
        name="密码"
        label="密码"
        placeholder="密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
    </van-cell-group>
    <div style="margin: 16px">
      <van-button round block type="primary" native-type="submit"> 提交 </van-button>
      <van-button round block type="danger" native-type="reset"> 重置 </van-button>
      <van-button round block type="success" @click="enterReg"> 去注册页 </van-button>
    </div>
  </van-form>
</template>

<script setup lang="ts" name="LoginPage">
import { reactive } from "vue";
import { useRouter } from "vue-router";
import useUserStore from "@/stores/user";
const userStore = useUserStore();
const router = useRouter();
const user = reactive({
  username: "",
  pwd: "",
});
const onSubmit = () => {
  userStore.userLog(user);
};

const enterReg = () => {
  router.replace("/reg");
};
</script>

<style scoped></style>
